<template>
  <el-row>
    <el-form-item label="简洁风格">
      <el-switch v-model="activeData.simple"/>
    </el-form-item>
    <el-form-item label="当前状态" v-show="showType==='pc'">
      <JnpfSelect v-model="activeData.processStatus" :options="processStatusOptions" :props="props"></JnpfSelect>
    </el-form-item>
    {{activeData.children}}
    <el-divider>步骤条配置</el-divider>
    <draggable :list="activeData.__config__.children" :animation="340" group="selectItem"
               handle=".option-drag"
    >
      <div v-for="(item, index) in activeData.__config__.children" :key="index" class="select-item">
        <div class="select-line-icon option-drag">
          <i class="icon-ym icon-ym-darg"/>
        </div>
        <el-input v-model="item.title" placeholder="步骤名称" size="small"/>
        <el-input v-model="item.icon" placeholder="请选择" v-show="showType==='pc'" :suffix-icon="item.icon">
          <el-button slot="append" @click="openIconsDialog(index)" size="small">
            选择
          </el-button>
        </el-input>
        <div class="close-btn select-line-icon" @click="delItem(index,item)">
          <i class="el-icon-remove-outline"/>
        </div>
      </div>
    </draggable>
    <div style="margin-left: 29px;">
      <el-button style="padding-bottom: 0" icon="el-icon-circle-plus-outline" type="text"
                 @click="addItem" class="!px-0"
      >
        添加步骤
      </el-button>
    </div>
    <iconBox :visible.sync="iconsVisible" :current="currentIcon" @choiceIcon="setIcon"/>

  </el-row>
</template>
<script>
import draggable from 'vuedraggable'
import comMixin from './mixin'
import iconBox from '@/components/JNPF-iconBox'

export default {
  props: ['activeData'],
  mixins: [comMixin],
  components: { draggable, iconBox },
  data() {
    return {
      iconsVisible: false,
      currentIcon: '',
      currentIndex: 0,
      props: {
        label: 'fullName',
        value: 'id'
      },
      processStatusOptions: [
        { id: 'wait', fullName: '等待' },
        { id: 'process', fullName: '进行中' },
        { id: 'finish', fullName: '完成' },
        { id: 'error', fullName: '错误' },
        { id: 'success', fullName: '成功' }
      ]
    }
  },
  created() {
  },
  methods: {
    openIconsDialog(index) {
      this.iconsVisible = true
      this.currentIndex = index
    },
    setIcon(val) {
      let item = this.activeData.__config__.children[this.currentIndex]
      item.icon = val
      this.$set( this.activeData.__config__.children ,this.currentIndex,item)
    },
    addItem() {
      const uuid = this.jnpf.idGenerator()
      this.activeData.__config__.children.push({
        title: '新步骤',
        name: uuid,
        icon: '',
        __config__: {
          jnpfKey: 'stepItem',
          children: []
        }
      })
      this.$set(this.activeData.__config__,'active',this.activeData.__config__.active+1)
    },
    delItem(index, item) {
      let list = this.activeData.__config__.children
      let length = list.length
      if (length < 3) {
        this.$message({
          message: '最后两项不能删除',
          type: 'warning'
        })
        return
      }
      this.$confirm('删除后不能撤销，确定要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.activeData.__config__.children.splice(index, 1)
        this.$set(this.activeData.__config__,'active',index-1)
      }).catch(() => {
      })
    }
  }
}
</script>
